import { IsNotEmpty, IsString, IsMobilePhone,IsEmail, IsInt} from "class-validator";
import { ApiErrorCode } from "../../ShareModule/enums/api-error-code";
import { ApiModelProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";

/**
 * @desc   DTO中不包含任何校验规则的字段将会被从请求体重直接提出
 * @author gebeibei
 * @date   3019-07-19
 */
export class UserDto{
    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"用户姓名必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    userName:string;

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"用户密码必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    passpord?:string;    

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"用户昵称必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    nickName:string;

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsMobilePhone('zh-CN',{
        message:"手机号格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"手机号必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    phone:string;

    @IsEmail({},{
        message:"邮箱格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"电子邮箱必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    email:string;

    @Type(()=> Number)
    @IsInt({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @ApiModelProperty()
    age:number;

    @Type(()=> Number)
    @IsInt({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @ApiModelProperty()
    gender:number;
}

export class editUserDto{
    @Type(() => Number)
    @IsNotEmpty({
        message:"用户id必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    id:number;

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"用户姓名必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    userName?:string;

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"用户密码必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    passpord?:string;    

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"用户昵称必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    nickName?:string;

    @IsString({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsMobilePhone('zh-CN',{
        message:"手机号格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"手机号必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    phone?:string;

    @IsEmail({},{
        message:"邮箱格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @IsNotEmpty({
        message:"电子邮箱必不可少",
        context:{errorCode:ApiErrorCode.PARAMS_LACK},
    })
    @ApiModelProperty()
    email?:string;

    @Type(()=> Number)
    @IsInt({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @ApiModelProperty()
    age?:number;

    @Type(()=> Number)
    @IsInt({
        message:"参数格式错误",
        context:{errorCode:ApiErrorCode.PARAMS_TYPE_ERROR},
    })
    @ApiModelProperty()
    gender?:number;
}